package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/nursing_project")
@RestController
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("护理项目分页查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam("护理项目名称，可模糊查询") String name,
            @ApiParam("第页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("状态，0禁用，1启用") Integer status) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(pageResponse);
    }

    @ApiOperation("新增护理项目")
    @PostMapping
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询护理项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @ApiOperation("修改护理项目")
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理项目")
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用/禁用护理项目")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
